/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { resolveHookDependency } from '../../../utils/task-util.js';
import { GenerateLoaderJson } from '../../generate-loader-json.js';
import { LegacyGenerateHarJsManifest } from '../../legacy-tasks/legacy-generate-har-js-manifest.js';
import { LegacyGenerateHarLoaderJson } from '../../legacy-tasks/legacy-generate-har-loader-json.js';
import { PreCheckSyscap } from '../../pre-check-syscap.js';
import { ModuleTaskService } from '../../service/module-task-service.js';
import { TargetTaskService } from '../../service/target-task-service.js';
import { PreviewHookCompileResource } from '../preview-hook-compile-resource.js';

import { AbstractPreviewerRes } from './abstract-previewer-res.js';

/**
 * for previewer hook only
 *
 * @since 2022/8/11
 */
export class BuildHarPreviewerRes extends AbstractPreviewerRes {
  constructor(moduleService: ModuleTaskService, isFaMode: boolean) {
    super(moduleService, isFaMode);
  }

  initTaskDepends(taskTargetService: TargetTaskService) {
    const targetName: string = taskTargetService.getTargetData().getTargetName();
    if (this._isFaMode) {
      this.dependsOn(resolveHookDependency(LegacyGenerateHarLoaderJson.name, targetName));
      this.dependsOn(resolveHookDependency(LegacyGenerateHarJsManifest.name, targetName));
    } else {
      this.dependsOn(resolveHookDependency(GenerateLoaderJson.name, targetName));
      this.dependsOn(resolveHookDependency(PreviewHookCompileResource.name, targetName));
    }

    this.dependsOn(resolveHookDependency(PreCheckSyscap.name, targetName));
  }
}
